package com.peanut.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.domain.bo.TabItemBO;
import com.peanut.domain.po.TabItemPO;
import com.peanut.service.TabItemService;
import com.peanut.mapper.TabItemMapper;
import com.peanut.util.IdWorker;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
* @author 张涛
* @description 针对表【tab_item】的数据库操作Service实现
* @createDate 2022-05-24 20:16:00
*/
@Service
public class TabItemServiceImpl extends ServiceImpl<TabItemMapper, TabItemPO>
    implements TabItemService{

    @Resource
    private TabItemMapper itemMapper;

    @Resource
    private IdWorker idWorker;

    @Override
    public int addItem(TabItemBO bo) {
        TabItemPO item = new TabItemPO();
        BeanUtils.copyProperties(bo,item);
        item.setItemId(idWorker.nextId());
        item.setItemUserId(1L);
        item.setItemCreateTime(new Date());
        return itemMapper.insert(item);
    }

    @Override
    public int deleteItem(Long itemId) {
        return itemMapper.deleteById(itemId);
    }

    @Override
    public Page<TabItemPO> findAll(Integer pageNumber, Integer pageSize) {
        Page<TabItemPO> item = new Page<>(pageNumber,pageSize);
        Page<TabItemPO> page1 = itemMapper.selectPage(item, null);
        return page1;
    }

    @Override
    public int updateItem(TabItemBO bo) {
        TabItemPO item = new TabItemPO();
        BeanUtils.copyProperties(bo,item);
        return itemMapper.updateById(item);
    }
}




